<template>
  <nav class="category-nav">
    <div class="view-all-button" @click="selectCategory(undefined)" :class="{ active: activeCategory === undefined }">
      <el-icon><View /></el-icon>
      <span>{{ $t('categories.all') }}</span>
    </div>
    <div class="nav-container">
      <div 
        v-for="category in categories" 
        :key="category.id"
        class="category-item"
        :class="{ active: activeCategory === category.id }"
        @click="selectCategory(category.id)"
        @mouseenter="handleHover(category)"
        @mouseleave="handleLeave"
      >
        <div class="icon-wrapper">
          <el-icon class="category-icon"><component :is="category.icon" /></el-icon>
          <div class="glow-effect" :class="{ active: activeCategory === category.id }"></div>
        </div>
        <span class="category-name">{{ category.name }}</span>
        <div class="light-beam" v-if="activeCategory === category.id"></div>
      </div>
    </div>
  </nav>
</template>

<script setup lang="ts">
import { ref, defineEmits } from 'vue'
import type { Category } from '@/types'
import { useUserStore } from '@/store/user'
import { View } from '@element-plus/icons-vue'

const props = defineProps<{
  categories: Category[]
  selectedCategory: number | undefined
}>()

const emit = defineEmits<{
  (e: 'select', categoryId: number | undefined): void
}>()

const userStore = useUserStore()
const activeCategory = ref<number | undefined>(props.selectedCategory)

const selectCategory = (categoryId: number | undefined) => {
  activeCategory.value = categoryId
  emit('select', categoryId)
}

const handleHover = (category: Category) => {
  if (activeCategory.value !== props.selectedCategory) {
    activeCategory.value = category.id
  }
}

const handleLeave = () => {
  activeCategory.value = props.selectedCategory
}
</script>

<style scoped lang="scss">
.category-nav {
  position: sticky;
  top: 20px;
  z-index: 10;
  padding: 20px;
  border-radius: 16px;
  background: var(--bg-color);
  box-shadow: var(--box-shadow);
  border: 1px solid var(--border-color);
  transition: all 0.3s ease;

  .view-all-button {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 20px;
    margin-bottom: 15px;
    border-radius: 8px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    background: var(--bg-color-secondary);
    color: var(--text-color);
    
    &.active {
      background: var(--menu-active-bg);
      color: var(--primary-color);
      font-weight: 600;
    }
    
    &:hover {
      background: var(--menu-hover-bg);
    }
    
    .el-icon {
      font-size: 18px;
    }
  }

  .nav-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
    
    .category-item {
      display: flex;
      align-items: center;
      padding: 10px 15px;
      border-radius: 8px;
      cursor: pointer;
      transition: all 0.3s ease;
      position: relative;
      color: var(--text-color);
      
      &.active {
        background: var(--menu-active-bg);
        color: var(--primary-color);
      }
      
      &:hover {
        background: var(--menu-hover-bg);
      }
      
      .icon-wrapper {
        position: relative;
        display: flex;
        align-items: center;
        justify-content: center;
        width: 36px;
        height: 36px;
        margin-right: 12px;
        background: var(--bg-color-secondary);
        border-radius: 8px;
        
        .category-icon {
          font-size: 18px;
          z-index: 2;
          color: var(--primary-color);
        }
        
        .glow-effect {
          position: absolute;
          inset: 0;
          z-index: 1;
          border-radius: 8px;
          transition: all 0.5s ease;
          opacity: 0;
          
          &.active {
            opacity: 1;
            box-shadow: 0 0 8px rgba(22, 119, 255, 0.3);
          }
        }
      }
      
      .category-name {
        font-weight: 500;
        font-size: 15px;
      }
      
      .light-beam {
        position: absolute;
        left: 0;
        top: 0;
        bottom: 0;
        width: 3px;
        background: var(--primary-color);
        border-radius: 3px;
      }
    }

    @media (min-width: 768px) {
      overflow-x: auto;
      padding-bottom: 10px;
      scroll-behavior: smooth;
      -webkit-overflow-scrolling: touch;
      
      &::-webkit-scrollbar {
        height: 4px;
      }
      
      &::-webkit-scrollbar-thumb {
        background: var(--border-color);
        border-radius: 4px;
      }
    }
  }
}

@media (max-width: 767px) {
  .category-nav {
    padding: 15px;
    .category-item {
      padding: 10px;
      .icon-wrapper {
        margin-right: 8px;
      }
    }
  }
}
</style> 